package com.zzjr.tools.java.ssm.table;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import java.awt.*;

/**
 * Description:
 * 
 * @Date Create on 2015年10月12日
 * @author <a href="mailto:Aromarich@zuozh.com">Aromarich</a>
 * @since version1.0 Copyright 2015 ZZJR All Rights Reserved.
 */
public class CheckBoxCellEditor extends AbstractCellEditor implements TableCellEditor {
	
	// ~ Static fields/initializers
	// -------------------------------------------------------------------------------------
	
	private static final long serialVersionUID = 1L;
	
	// ~ Instance fields
	// ------------------------------------------------------------------------------------------------
	
	protected JCheckBox checkBox;
	
	// ~ Constructors
	// ---------------------------------------------------------------------------------------------------
	
	public CheckBoxCellEditor() {
		checkBox = new JCheckBox();
		checkBox.setHorizontalAlignment(SwingConstants.CENTER);
		// checkBox.setBackground( Color.white);
	}
	
	// ~ Methods
	// --------------------------------------------------------------------------------------------------------
	
	@Override
	public Object getCellEditorValue() {
		return Boolean.valueOf(checkBox.isSelected());
	}
	
	// ~
	// ----------------------------------------------------------------------------------------------------------------
	
	@Override
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
		checkBox.setSelected(((Boolean) value).booleanValue());
		
		return checkBox;
		
	}
} // end class CheckBoxCellEditor
